

***************
*** Table 4 ***
***************

clear all

*Set the folder where data are
cd ""

use B2_correct,clear

*drop HH and workers observed only once
drop if honeobsfyr==1
drop if wnyrsp==1

bysort dhcode year: gen counter = _n == 1   // create a dummy variable 1 for first HH obs in a year, 0 otherwise
by dhcode: replace counter = sum(counter)     // sum the 1s and 0s only within HH, hence the first year that first member in HH is observed is 1, the second year is 2 etc
by dhcode: egen hhnyrsp = max(counter)     //  within HH replaces all values with the highest to give the HH number of years in the UHS
label var hhnyrsp "HH total number of years in UHS panel"
tab hhnyrsp 
drop if hhnyrsp==1

xtset dhcode year

*** county specific trends
quiet tab countyid, gen(countytrend)
quiet for num 1/658: replace countytrendX=countytrendX*year

*** city specific trends
quiet tab cityid, gen(citytrend)
quiet for num 1/194: replace citytrendX=citytrendX*year
replace citygovbalgdp=. if citygovbalgdp<-20
gen lncitygovexp=ln(citygovexp)

** tabulate industries because xtivreg2 does not take factor variables
set more off
tab industryH, gen(indH)
tab industryS, gen(indS)
tab occupationH, gen(occH)
tab occupationS, gen(occS)
tab maritstatusH, gen(marH)
tab maritstatusS, gen(marS)
tab educH, gen(edH)
tab educS, gen(edS)
tab educ2H, gen(ed2H)
tab educ2S, gen(ed2S)


*** gen provinceXtime FE since xtivreg does not use factor variables
set more off
egen provxyr = group(provid year)
tab provxyr, gen(pxy)
egen cityxyr = group(cityid year)
tab cityxyr, gen(cxy)

drop if hMWshare==.


*Controls
global xhhiv familysize houseown genderH genderS ageH ageS age2H age2S wexperH wexperS wexper2H wexper2S migrH migrS migr2H migr2S hhrealotherincUHS hhrealhsln 

*City
global xcity lnrealcitygdp lnrealcitysalary cityunemplrate citypop       


gen hhhealtheducexp = hhhealthcons+hheduccons


*Eliminate mechanical correlation
drop if year==2002
set matsize 2000


*Table 4
est clear 
set more off
xtivreg2 hhhealtheducexp (hhreallabinc = effrealmw) $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare==0,  fe robust cluster(countyid)
est sto m1
xtivreg2 hhhealtheducexp (hhreallabinc = effrealmw) $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.5, fe robust cluster(countyid)
est sto m2
xtivreg2 hhhealtheducexp (hhreallabinc = effrealmw) $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.75, fe robust cluster(countyid)
est sto m3
xtivreg2 hhnondurabcons (hhreallabinc = effrealmw) $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare==0,  fe robust cluster(countyid)
est sto m4
xtivreg2 hhnondurabcons (hhreallabinc = effrealmw) $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.5,  fe robust cluster(countyid)
est sto m5
xtivreg2 hhnondurabcons (hhreallabinc = effrealmw) $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.75, fe robust cluster(countyid)
est sto m6
xtivreg2 hhdurablescons (hhreallabinc = effrealmw) $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare==0, fe robust cluster(countyid)
est sto m7
xtivreg2 hhdurablescons (hhreallabinc = effrealmw) $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.5,  fe robust cluster(countyid)
est sto m8
xtivreg2 hhdurablescons (hhreallabinc = effrealmw) $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.75,  fe robust cluster(countyid)
est sto m9

estout m1 m2 m3 m4 m5 m6 m7 m8 m9 using "Table IV.tex", style(tex) cells(b(fmt(3)) se(star par fmt(3))) delim("&") numbers starlevels(* 0.10 ** 0.05 *** 0.01) ///
collabels( , none) mlabels("$ S=0 $" "$ S>0.5 $" "$ S>0.75 $" "$ S=0 $" "$ S>0.5 $" "$ S>0.75 $" "$ S=0 $" "$ S>0.5 $" "$ S>0.75 $") ///
mgroups("Health \& Educ. Exp." "Non-durables Exp." "Durables Exp.", lhs(Dep.var.: ) pattern(1 0 0 1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
stats(N N_clust N_g idp, fmt(0 0 0 3 3) label(Observations "N clusters" "N households" "Irrelevant instr. (pval)")) ///
keep(hhreallabinc) varlabels(hhreallabinc "Household labor income") varwidth(20) modelwidth(10) ///
prehead("\begin{table}[tbhp] \centering \resizebox{\textwidth}{!} { \begin{tabular}{l*{9}{c}}" \toprule) posthead(\cmidrule(rl){2-4}\cmidrule(rl){5-7}\cmidrule(rl){8-10} \\) ///
prefoot( \\ HH member controls & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\ HH-level controls & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes \\ City-level controls & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\ Household FE & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes \\  Prov $\times$ year FE & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\ County Trend & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\  ) postfoot( \bottomrule "\end{tabular} } \end{table} ") replace


